package client.superadmin;

import static org.stjs.javascript.JSCollections.$array;

import org.stjs.javascript.Array;
import org.stjs.javascript.Map;

import client.common.EndPoints.SupadminEP;
import client.common.Models.Materia;
import client.common.angular.NgScope;
import client.common.directives.EPChanging;
import client.common.directives.EPLoading;
import client.common.javascript.JsProcedure0;

public class ColMateriaScope extends NgScope {

	private Materia materia;
	private EPChanging epChanging;
	private SupadminEP superadminEP;
	private EPLoading epLoading;

	public ColMateriaScope(final Map<String, Long> $stateParams,
			final SupadminEP superadminEP, EPChanging epChanging,
			EPLoading epLoading) {
		super("ColGradoScope");

		this.epChanging = epChanging;
		this.superadminEP = superadminEP;
		this.epLoading = epLoading;

		this.materia = superadminEP.getMateria($stateParams.$get("idMateria"));
		//

	}

	public void materiaChange() {
		final ColMateriaScope that = this;
		epChanging.$invoke(this, 1300, new JsProcedure0() {
			public void $invoke() {
				that.epLoading.$invoke(that.superadminEP.updateMateria(
						that.materia.id, that.materia), "div[datos]");
			}
		});
	}

	public static Array<String> $inject() {
		return $array("$stateParams", "Superadmin", "epChanging", "epLoading");
	}

}
